<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>案例</title>
</head>
<body>
    用户名: <input type="text" id="username">
    <span id="sp1" style="display: none;color: red">用户名已存在</span>
    <p></p>
    <script>
        function handle(data) {
            if (data===true){
                // console.log('存在')
                document.getElementById('sp1').style.display = ''
            }else {
                // console.log('不存在')
                document.getElementById('sp1').style.display = 'none'
            }
        }

        let user_input = document.getElementById('username')
        user_input.onblur = function () {
            // let user_input = document.getElementById('username')
            let script1 = document.createElement('script')
            script1.src = 'http://127.0.0.1:8000/check-username?username='+user_input.value

            document.body.appendChild(script1)
        }
    </script>
</body>
</html>